package main

import (
	"gorule/core"
	"log"
	"reflect"
)

// 深度优先遍历规则树
func main() {
	r := core.OrRule(
		core.Rule(
			func(ctx *core.Context) bool {
				return false
			},
			func(ctx *core.Context) {

			},
		),
		core.OrRule(
			core.Rule(
				func(ctx *core.Context) bool {
					return true
				},
				func(ctx *core.Context) {

				},
			),
			core.OrRule(
				core.Rule(
					func(ctx *core.Context) bool {
						return true
					},
					func(ctx *core.Context) {

					},
				),
				core.Rule(
					func(ctx *core.Context) bool {
						return true
					},
					func(ctx *core.Context) {

					},
				),
			),
		),
		core.AndRule(
			core.Rule(
				func(ctx *core.Context) bool {
					return true
				},
				func(ctx *core.Context) {

				},
			),
			core.Rule(
				func(ctx *core.Context) bool {
					return true
				},
				func(ctx *core.Context) {

				},
			),
		),
		core.NotRule(core.Rule(
			func(ctx *core.Context) bool {
				return true
			},
			func(ctx *core.Context) {

			},
		)),
	)

	core.TraverseDFS(r, func(rule core.BaseRule) error {
		log.Println("DFS", reflect.TypeOf(rule))
		return nil
	})

	log.Println()
	core.TraverseBFS(r, func(rule core.BaseRule) error {
		log.Println("BFS", reflect.TypeOf(rule))
		return nil
	})
}
